package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.service.CsLoginService;
import cn.cs.service.CsUserInfoService;
import cn.cs.vo.CsUserVO;
import cn.cs.vo.QueryUserVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * yuexl
 */
@Controller
@RequestMapping("/api/v")
public class CsUserInfoController {
    private static final Logger logger = LoggerFactory.getLogger(CsUserInfoController.class);
    @Resource
    private CsUserInfoService csUserInfoService;

    @Resource
    private CsLoginService csLoginService;

    /**
     * 根据用户的id查询用户信息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryUserInfoByToken", method = RequestMethod.POST, produces = {"application/json"})
    @ResponseBody
    public Dto queryUserInfoById(@RequestHeader String token) throws Exception {
        CsUserVO csUserVO= csLoginService.loadCurrentUserByTokenAsCsUserVo(token);
        logger.info("[queryUserInfoById]" + "获取用户信息成功，用户名为："+csUserVO.getNickName());
        QueryUserVo queryUserVo = csUserInfoService.queryUserInfoById(csUserVO.getUserId());
        return DtoUtil.returnDataSuccess(queryUserVo);
    }

    /**
     * 修改用户信息-初版
     * @param queryUserVo
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifyUserInfo", method = RequestMethod.POST, produces = {"application/json"})
    @ResponseBody
    public Dto modifyUserInfo(@RequestBody QueryUserVo queryUserVo,@RequestHeader String token) throws Exception{
        CsUserVO csUserVO= csLoginService.loadCurrentUserByTokenAsCsUserVo(token);
        queryUserVo.setId(csUserVO.getUserId());
        logger.info("[modifyUserInfo]" + "修改用户信息，用户id为："+csUserVO.getUserId());
        Integer i = csUserInfoService.qdtxModifyCsUser(queryUserVo);
        return DtoUtil.returnSuccess();
    }



}
